<@admin.header title="汽车图片集">
<@common.validate/>
<script type="text/javascript">
    $(document).ready(function(){
		$('#mainForm').validate();
		
		App.ns('M');

		M.del = function(id){
			App.Msg.confirm("确定删除这个图片吗？",function(){
				App.ajax.post("car/picture/delete.do",{id:id},function(d){
					if(d.success){
						App.toast.success("图片删除成功");
						$("#li_"+id).hide();
					}
					else
						App.Msg.alert(d.message);
				});
			});
		}
		
		/*
		 * 上传新图片
		 */
		M.upload = function(){
			//每次上传前都清空队列
			$('#uploader').plupload('clearQueue');
			App.Msg.show("uploadDiv","上传图片",function(){
				window.location.reload();
			});
		}
		//更新排序
		M.sort=function(id, sort){
			App.Msg.prompt("请输入排序值（越大越靠前）", function(v){
				if(isNaN(v)){
					App.Msg.alert("请输入数字");
					return false;
				}
				App.ajax.post("car/picture/sort.do",{id:id,sort:v},function(d){
					if(d.success){
						//window.location.href="${base}/car/picture.do?id="+${entity.id};
						window.location.reload();
					}
					else
						App.Msg.alert(d.message);
				});
			},sort);
		}
    });
</script>

</@admin.header>
<body>
    <div class="place">
        <span>位置：</span>
        <ul class="placeul">
            <li>
                <a href="${base}/right.do">首页</a>
            </li>
            <li>
                <a href="list.do">二手车管理</a>
            </li>
            <li>
                <a href="">汽车图片集</a>
            </li>
        </ul>
    </div>
	<div class="rightinfo">
		<@nerve.carEditNav nav="${template}" />
		
        <!--默认查询表单-->
        <div class="tools">
                <ul class="toolbar">
                    <li class="click">
                        <a href="javascript:M.upload();"><span><img src="${base}/resources/images/t01.png" /></span>添加</a>
                    </li>
                </ul>
        </div>
		
        <ul class="imglist">
            <#list entity.pictures as p>
			<li id="li_${p.id}">
                <span><img src="${base}${p.path}" /></span><h2><a href="javascript:;">${p.fileName}</a></h2>
                <p>
                    <a href="javascript:;" onclick="M.sort(${p.id},'${p.sort}');">编辑</a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="javascript:;" onclick="M.del(${p.id})">删除</a>
                </p>
            </li>			
			</#list>
        </ul>
		
		<div id="uploadDiv" class="hide" style="width:600px;">
		<form action="picture/upload.do?id=${entity.id}" method="post" id="mainForm" enctype="multipart/form-data">
		    <div class="formbody">
				<div class="formtext">
					Hi，推荐的文件大小为<b>600</b>*<b>450</b>px（或者同比例更大的图片像素），否则会造成图片变形影响美观
				</div>
		        <ul class="forminfo2">
		            <@common.upload_plupload name='upload_file' url='picture/uploadAjax.do?id=${entity.id}'/>
		        </ul>
		    </div>
		</form>
		</div>
    </div><!-- Definition of context menu -->
	
	<script>
		$(document).ready(function(){
			<#if error??>
			App.Msg.alert("${error}");
			</#if>
		});
		
		//图片上传完后，刷新页面
		$('#uploader').on("complete", function(){
			//alert("上传完成");
			//window.location.reload();
		});
	</script>
</body>
</html>